Python: Pickling highly-recursive objects without using `setrecursionlimit`

Posted by cool-RR on Stack Overflow See other posts from Stack Overflow or by cool-RR
Published on 2010-05-26T12:22:00Z Indexed on 2010/06/15 23:52 UTC
Read the original article Hit count: 207

Filed under:
|
|

I've been getting RuntimeError: maximum recursion depth exceeded when trying to pickle a highly-recursive tree object. Much like this asker here.

He solved his problem by setting the recursion limit higher with sys.setrecursionlimit. But I don't want to do that: I think that's more of a workaround than a solution. Because I want to be able to pickle my trees even if they have 10,000 nodes in them. (It currently fails at around 200.)

(Also, every platform's true recursion limit is different, and I would really like to avoid opening this can of worms.)

Is there any way to solve this at the fundamental level? If only the pickle module would pickle using a loop instead of recursion, I wouldn't have had this problem. Maybe someone has an idea how I can cause something like this to happen, without rewriting the pickle module?

Any other idea how I can solve this problem will be appreciated.

© Stack Overflow or respective owner

Related posts about python

Related posts about recursion